package easy;

public class Solution_1351 {

    public int countNegatives(int[][] grid) {
        int count = 0;
        int col = 0, c_len = grid[0].length;
        for (int r = grid.length - 1; r >= 0 && col < c_len; r--) {
            for (; col < c_len; col++) {
                if (grid[r][col] < 0) {
                    break;
                }
            }
            count += (c_len - col);
        }
        return count;
    }

    public static void main(String[] args) {
        Solution_1351 model = new Solution_1351();
        System.out.println(model.countNegatives(new int[][]{{4, 3, 2, -1}, {3, 2, 1, -1}, {1, 1, -1, -2}, {-1, -1, -2, -3}}));
        System.out.println(model.countNegatives(new int[][]{{3, 2}, {1, 0}}));
        System.out.println(model.countNegatives(new int[][]{{-1}}));
    }
}
